package csp;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class MapColoringConstraint implements Constraint<String,String> {
	
	private String value1;

	private String value2;
	
	//二元约束
	public MapColoringConstraint(String value1,String value2) {
		this.value1 = value1;
		this.value2 = value2;
	}
	
	@Override
	public boolean satisfied(Map<String,String> assignment) {
		/**
		String getValue1 = assignment.get(value1);
		String getValue2 = assignment.get(value2);
		if(getValue1==null||getValue2==null) {
			return true;
		}
		return !(getValue1.equals(getValue2));
		*/
		return !Objects.equals(assignment.get(value1),assignment.get(value2));//判断是否同色
	}
	
	@Override
	public List<String> getVariables() {
		return List.of(value1,value2);
	}

}